<template>
	<view class="hall_wrap">
		<view class="flex nav_wrap">
			<view :class="nav_index == 0 ? 'nav_item active' : 'nav_item'" @click="toNav(0)">供需大厅</view>
			<view :class="nav_index == 1 ? 'nav_item active' : 'nav_item'" @click="toNav(1)">供应商</view>
		</view>
		<view class="up_item" @click="toUp()">
			<image :src="remoteUrl + 'up_icon.png'" class="up_icon" mode=""></image>
			<text>我要发布</text>
		</view>
		<scroll-view scroll-y="true" style="height: calc(100vh - 98rpx);" v-if="nav_index == 0">
			<view class="list_wrap">
				<view class="flex-col list-item mt-10" v-for="(item,index) in list" @click="toDetail(item.id)">
					<view class="flex-row justify-between items-center">
						<text class="font_5 row_1" style="width: 80%;">{{ item.title }}</text>
						<view class="flex">
							<view class="flex-col justify-start items-center text-wrapper view" v-if="item.type_id == 1">
								<text class="font_6">供</text>
							</view>
							<view class="flex-col justify-start items-center text-wrapper need" v-if="item.type_id == 2">
								<text class="font_6">需</text>
							</view>
							<view class="flex-col justify-start items-center text-wrapper not" v-if="item.status == 0">
								<text class="font_6">未解决</text>
							</view>
							<view class="flex-col justify-start items-center text-wrapper already" v-if="item.status == 1">
								<text class="font_6">已解决</text>
							</view>
						</view>
					</view>
					<!-- <text class="font_7 mt-14 row_1">{{ item.content }}</text> -->
					<rich-text class="font_7 mt-14 row_1" :nodes="item.content"></rich-text>
					<view class="flex-row justify-between items-center mt-14">
						<view class="flex-row items-center">
							<image class="image_9" :src="ossUrl + item.user_avatar" />
							<text class="font_8 text_10">{{ item.user_name }}</text>
							<view class="section_10"></view>
							<text class="font_8 text_31">{{ item.user_company_name }}</text>
						</view>
						<text class="font_9 text_12">{{ item.updatetime }}</text>
					</view>
				</view>
			</view>
		</scroll-view>
		<scroll-view scroll-y="true" style="height: calc(100vh - 98rpx);" v-if="nav_index == 1">
			<view class="list_wrap">
				<view class="flex-row mt-10 list-items" v-for="(item,index) in company_list" @click="companyDetail(item.id)">
					<image class="self-start image_7" :src="ossUrl + item.images" />
					<view class="flex-col flex-1 self-center ml-10">
						<text class="self-start font text_5">{{ item.name }}</text>
						<text class="self-stretch font_2 text_2 text_6 row_3">
							{{ item.introduce }}
						</text>
						<!-- <text class="self-start font_2 text_2 text_7 row_1">这是一段供应商简介这是一段供应商简介这是一段供应商简介...</text> -->
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		remoteUrl,
		ossUrl
	} from '@/utils/config.js'
	import {
		task_list,
		companyList
	} from '@/api/home.js'
	export default {
		data() {
			return {
				ossUrl: ossUrl,
				remoteUrl: remoteUrl,
				nav_index: 0,
				list: [],   // 供需列表
				company_list: [],  // 供应商列表
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.getList()
			this.getCompanyList()
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: '小程序分享',
				imageUrl: '',
			}
		},
		methods: {
			getList() {
				task_list().then(res => {
					if (res.code == 1) {
						this.list = res.data
					}
				})
			},
			// 供应商列表
			getCompanyList() {
				companyList().then(res => {
					if (res.code == 1) {
						this.company_list = res.data
					}
				})
			},
			toUp() {
				uni.navigateTo({
					url: '/pages/pages-list/publish_demand/publish_demand'
				})
			},
			toNav(index) {
				this.nav_index = index
			},
			toDetail(id) {
				if (!uni.getStorageSync('userInfo')) {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
				uni.navigateTo({
					url: '/pages/pages-list/demand_detail/demand_detail?id=' + id
				})
			},
			companyDetail(id) {
				if (!uni.getStorageSync('userInfo')) {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
				uni.navigateTo({
					url: '/pages/pages-list/company_detail/company_detail?id=' + id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.hall_wrap {
		height: 100vh;
		background: #F5F5F5;

		.nav_wrap {
			width: 100vw;
			height: 96rpx;
			align-items: center;
			padding: 0 28rpx;
			background: #fff;

			.nav_item {
				font-size: 30rpx;
				color: #989595;
				margin-right: 80rpx;
			}

			.active {
				color: #1C41F1;
				font-weight: bold;
				position: relative;
			}

			.active::after {
				content: "";
				width: 60rpx;
				border-bottom: 6rpx solid #1C41F1;
				position: absolute;
				bottom: -10rpx;
				left: 50%;
				transform: translate(-50%);
			}
		}

		.up_item {
			width: 180rpx;
			height: 64rpx;
			background: #70D042;
			border-radius: 32rpx 0rpx 0rpx 32rpx;
			position: fixed;
			bottom: 190rpx;
			right: 0;
			z-index: 10;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 24rpx;
			.up_icon {
				width: 48rpx;
				height: 48rpx;
				margin-right: 8rpx;
			}
		}

		.list_wrap {
			.list-item {
				width: 690rpx;
				margin: 20rpx auto;
				padding: 22rpx 11.86rpx 16rpx 17.72rpx;
				background-color: #ffffff;
				border-radius: 12rpx;

				.font_5 {
					font-size: 30rpx;
					font-family: PingFang SC;
					color: #000000;
				}

				.text-wrapper {
					margin-right: 10rpx;

					.font_6 {
						font-size: 24rpx;
						font-family: PingFang SC;
						color: #ffffff;
					}
				}

				.view {
					padding: 3rpx 7rpx;
					background-color: #70d042;
					border-radius: 4rpx;
				}

				.need {
					padding: 3rpx 7rpx;
					background-color: #f8d53a;
					border-radius: 4rpx;
				}

				.not {
					padding: 3rpx 7rpx;
					background-color: #999999;
					border-radius: 4rpx;
				}
				.already {
					padding: 3rpx 7rpx;
					border-radius: 4rpx;
					background: #1C41F1;
				}

				.font_7 {
					font-size: 24rpx;
					font-family: PingFang SC;
					color: #000000;
				}

				.image_9 {
					border-radius: 20rpx;
					width: 40rpx;
					height: 40rpx;
				}

				.font_8 {
					font-size: 22rpx;
					font-family: PingFang SC;
					color: #000000;
				}

				.text_10 {
					margin-left: 9.08rpx;
				}

				.section_10 {
					margin-left: 15.92rpx;
					background-color: #d9d9d9;
					width: 2rpx;
					height: 24rpx;
				}

				.text_31 {
					margin-left: 14.84rpx;
				}

				.font_9 {
					font-size: 20rpx;
					font-family: PingFang SC;
					color: #000000;
				}

				.text_12 {
					margin-right: 4rpx;
				}
			}
		
			.list-items {
				width: 690rpx;
			  margin: 28rpx auto;
			  padding: 20rpx;
			  background-color: #ffffff;
			  border-radius: 12rpx;
			  .image_7 {
			    border-radius: 10rpx;
			    width: 100rpx;
			    height: 100rpx;
			  }
			  .font {
			    font-size: 30rpx;
			    color: #000000;
			  }
			  .text_5 {
			    opacity: 0.9;
			  }
			  .font_2 {
			    font-size: 24rpx;
			    color: #000000;
			  }
			  .text_2 {
			    opacity: 0.5;
			  }
			  .text_6 {
				  width: 80%;
			    margin-top: 20rpx;
			  }
			  .text_7 {
				width: 80%;
			    margin-top: 6rpx;
			  }
			}
		}
	}
</style>